package com.atguigu.stgy.admin.controller;

import com.atguigu.stgy.admin.service.ViewAppointmentService;
import com.atguigu.stgy.model.dto.AppointmentSearchDTO;
import com.atguigu.stgy.model.entity.ViewAppointment;
import com.atguigu.stgy.model.result.R;
import com.atguigu.stgy.model.vo.AppointmentVO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


/**
 * 预约看房信息表(view_appointment)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/admin/appointment")
public class ViewAppointmentController {
    /**
     * 服务对象
     */
    @Resource
    private ViewAppointmentService viewAppointmentService;

    ///admin/appointment/updateStatusById?id=2&status=3
    @Operation(summary = "更新看房预约状态")
    @PostMapping("updateStatusById")
    public R updateStatusById(@RequestParam("id") Long id,
                              @RequestParam("status") Integer status) {
        viewAppointmentService.update(Wrappers.lambdaUpdate(ViewAppointment.class)
                .eq(ViewAppointment::getId , id)
                .set(ViewAppointment::getAppointmentStatus , status)
                .set(ViewAppointment::getUpdateTime , new Date()));
        //响应数据给前端
        return R.ok();
    }

    ///admin/appointment/page?current=1&size=10&provinceId=11&cityId=1101&name=323&phone=23213123
    @Operation(summary = "条件查询预约分页列表")
    @GetMapping("page")
    public R<Page<AppointmentVO>> page(AppointmentSearchDTO searchDTO) {
        //接受请求参数
        Page<AppointmentVO> page = viewAppointmentService.pageItem(searchDTO);
        //响应数据给前端
        return R.ok(page);
    }
}
